package 
{
	import alternativa.engine3d.core.Mesh;
	import alternativa.engine3d.events.MouseEvent3D;
	import alternativa.engine3d.materials.TextureMaterial;
	
	import flash.display.BlendMode;
	import flash.geom.Point;
	

	public class BoutonAscenseur extends Mesh {
		
		private var largeur:int=3;
		private var hauteur:int=3;
		private var numeroAscenseur:int;
		private var numeroEtage:int;
		private var brille:Boolean;

		private var bouton:TextureMaterial;
		private var bouton_a:TextureMaterial;
		

		public function BoutonAscenseur(numAsc:int,numEtage:int):void
		{
			super("Bouton"+numEtage);
			numeroAscenseur=numAsc;
			numeroEtage=numEtage;
			
			
			bouton=new TextureMaterial(LoaderTexture.getTextureBouton(numeroEtage), 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			bouton_a=new TextureMaterial(LoaderTexture.getTextureBouton(10+numeroEtage), 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			
			createVertex(0,0,0,1);
            createVertex(largeur,0,0,2);
			createVertex(largeur,0,hauteur,3);
			createVertex(0,0,hauteur,4);
            
            
			createFace([1,4,3,2],"BoutonFace");
			setUVsToFace(new Point(1,0), new Point(1,1), new Point(0,1), "BoutonFace");
			createSurface(["BoutonFace"], "BoutonSurface");
			placement();
			eteint();
			
			addEventListener(MouseEvent3D.CLICK,onClick);
		}
		
		public function onClick(e:MouseEvent3D):void{
			(Ascenseur)(this.scene.root.getChildByName("Ascenseur"+numeroAscenseur)).appelAscenseur(numeroEtage);
			allume();
		}
		
		public function placement():void{
			this.x=13.5;
			this.y=0.2;
			this.z=10+numeroEtage*5;
		}
		
		public function allume():void{
			setMaterialToSurface(bouton_a, "BoutonSurface");
			brille=true;
		}
		public function eteint():void{
			setMaterialToSurface(bouton, "BoutonSurface");
			brille=false;
		}
		
		public function estAllume():Boolean{
			return brille;
		}
	}
}